package com.mdlib.helper.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.ljlib.core.R;


/**
 * 作者：HQY on 16/12/2 15:51
 * 邮箱：hqy_xz@126.com
 */

public class HelperWaitDialog {

    private Dialog mWaitDialog;

    private ImageView mIvHelperWait;
    private AnimationDrawable anim;

    public HelperWaitDialog(Context context, boolean isCheck) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_wait, null);
        // 获取整个布局
        LinearLayout layout = (LinearLayout) view.findViewById(R.id.dialog_view);
        mIvHelperWait = (ImageView) view.findViewById(R.id.iv_helper_wait);
        anim = (AnimationDrawable) mIvHelperWait.getBackground();
        // 创建自定义样式的Dialog
        mWaitDialog = new Dialog(context, R.style.helper_wait);
        // 设置返回键无效
        mWaitDialog.setCancelable(isCheck);
        mWaitDialog.setContentView(layout, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT));

    }

    public void show() {
        if (mWaitDialog == null) {
            mWaitDialog.show();
            anim.start();
        }
    }

    public void close() {
        if (mWaitDialog != null) {
            anim.stop();
            mWaitDialog.dismiss();
            mWaitDialog = null;
        }
    }
}
